<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <div class="container">
        <div class="block">
          <span class="demonstration">按月搜索   </span>
          <el-date-picker
            v-model="queryParams"
            type="month"
            @click="getList"
            placeholder="选择月">
          </el-date-picker>
        </div>
      </div>


    </el-form>


    <el-collapse v-model="activeNames" >
      <el-collapse-item v-for="(item, index) in payoff.deptInfo" :key="index" :title="`${item.sysDept.deptName}: ${item.deptSum}`" >
<!--        <p v-for="(man,indec) in item.actuallyWages">{{man}}</p>-->
        <el-table  :data="item.actuallyWages" >
          <el-table-column label="员工名称" align="center" prop="userName" />
          <el-table-column label="本月工资" align="center" prop="wageSum" />
        </el-table>
      </el-collapse-item>
    </el-collapse>

    <el-row :gutter="10" class="mb8">
    <h1>工资总计:{{payoff.allSum}}</h1>
    </el-row>


    <!-- 添加或修改培训对话框 -->
  </div>
</template>

<script>
import { listAllWage } from "@/api/checkingin/actuallyWage";
export default {
  name: "Train",
  data() {
    return {
      mouthTime: '',
      payoff:{},

      baseUrl: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 培训表格数据
      trainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: "2024-3",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询培训列表 */
    getList() {
      this.loading = true;
      listAllWage(this.queryParams).then(response => {
        this.payoff = response.data;
        console.log(response);
      /*  // 使用 Array.map() 添加索引序号
        this.trainList = this.trainList.map((record, index) => {
          // 添加名为 "index" 的属性，其值为索引序号
          return { ...record, index: index + 1 };
        });
        this.total = response.total;
        this.loading = false;*/
      });
    },
    getDeptUser(item) {
      const actuallyWages = [];
      for (const dept of this.payoff.deptInfo) {
        if (dept.sysDept.deptId === item) {
          // 假设用户列表存储在 dept.users 中，将用户列表添加到 actuallyWages 数组中
          actuallyWages.push(...dept.users);
          // 如果只需要返回部门信息而不需要用户列表，则可以直接返回 dept
          // return dept;
        }
      }
      return actuallyWages;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        uId: null,
        name: null,
        filePath: null,
        introduce: null,
        startTime: null,
        overTime: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('train/train/export', {
        ...this.queryParams
      }, `train_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>
